﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model_SSResourceManager;
using Presenter_SSResourceManager;

namespace WebView_SSResourceManager.Admin
{
    public partial class AddResource : System.Web.UI.Page, IViewAddResource
    {
        public PresenterAddResoure AddResourePresenter; 

        public AddResource()
        {
            this.AddResourePresenter = new PresenterAddResoure(this);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
                AddResourePresenter.CreateNew();
            
            
        }

        public Resource GatherPageFieldsInformation()
        {
            return new Resource() 
            { 
                Id = (Guid)Session["TempId"],
                EndTime = TimeSpan.Parse(txtB_EndTime.Text),
                StartTime = TimeSpan.Parse(txtB_StartTime.Text),
                TimeOfUsing = TimeSpan.FromMinutes(double.Parse(txtB_UsingTime.Text)),
                Locked = chB_Locked.Checked,
                Name = txtB_Name.Text,
                OnlyAutoTime = chB_AutoTime.Checked,
                UserCount = Int32.Parse(txtB_UserCount.Text)
            };
            
        }

        public void FillEmptyResourcePattern(Resource resource)
        {
            Session["TempId"] = resource.Id;
            txtB_EndTime.Text = resource.EndTime.ToString();
            txtB_StartTime.Text = resource.StartTime.ToString();
            txtB_UsingTime.Text = resource.TimeOfUsing.TotalMinutes.ToString();
            txtB_Name.Text = resource.Name;
            txtB_UserCount.Text = resource.UserCount.ToString();
            chB_AutoTime.Checked = resource.OnlyAutoTime;
            chB_Locked.Checked = resource.Locked;
        }

        protected void Submit_OnClick(object sender, EventArgs e)
        {
            AddResourePresenter.AddNew();
            Response.Write("okay");
            AddResourePresenter.CreateNew();
        }

    }
}